<template>
  <el-dialog
    :title="title"
    :close-on-click-modal="false"
     v-dialogDrag
    :visible.sync="visible">
    <el-form size="small" :model="inputForm" ref="inputForm" :class="method==='view'?'readonly':''"  :disabled="method==='view'" @keyup.enter.native="doSubmit()"
             label-width="120px">
      <el-row  :gutter="15">
        <el-col :span="12">
            <el-form-item label="全日制学历学位" prop="fullEducation"
                :rules="[
                 ]">
              <el-input v-model="inputForm.fullEducation" placeholder="请填写全日制学历学位"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="全日制毕业院校及专业" prop="fullGraduate"
                :rules="[
                 ]">
              <el-input v-model="inputForm.fullGraduate" placeholder="请填写全日制毕业院校及专业"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="全日制起始时间" prop="fullStart"
                :rules="[
                 ]">
              <!-- <el-input v-model="inputForm.fullStart" placeholder="请填写全日制起始时间"     ></el-input> -->
              <el-date-picker
                    value-format="yyyy.MM"
                    v-model="inputForm.fullStart"
                    type="month"
                    placeholder="选择全日制起始日期">
                  </el-date-picker>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="全日制结束时间" prop="fullEnd"
                :rules="[
                 ]">
              <!-- <el-input v-model="inputForm.fullEnd" placeholder="请填写全日制结束时间"     ></el-input> -->
              <el-date-picker
                value-format="yyyy.MM"
                v-model="inputForm.fullEnd"
                type="month"
                placeholder="选择全日制结束日期">
              </el-date-picker>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="在职教育学历学位" prop="nowEducation"
                :rules="[
                 ]">
              <el-input v-model="inputForm.nowEducation" placeholder="请填写在职教育学历学位"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="在职教育毕业专业" prop="nowGraduate"
                :rules="[
                 ]">
              <el-input v-model="inputForm.nowGraduate" placeholder="请填写在职教育毕业专业"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="在职教育起始时间" prop="nowStart"
                :rules="[
                 ]">
              <!-- <el-input v-model="inputForm.nowStart" placeholder="请填写在职教育起始时间"     ></el-input> -->
              <el-date-picker
                value-format="yyyy.MM"
                v-model="inputForm.nowStart"
                type="month"
                placeholder="选择在职教育起始日期">
              </el-date-picker>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="在职教育结束时间" prop="nowEnd"
                :rules="[
                 ]">
              <!-- <el-input v-model="inputForm.nowEnd" placeholder="请填写在职教育结束时间"     ></el-input> -->
              <el-date-picker
                value-format="yyyy.MM"
                v-model="inputForm.nowEnd"
                type="month"
                placeholder="选择在职教育结束日期">
              </el-date-picker>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="最高学历/学位" prop="lastEducation"
                :rules="[
                 ]">
              <el-input v-model="inputForm.lastEducation" placeholder="请填写最高学历/学位"     ></el-input>
           </el-form-item>
        </el-col>
        <!-- <el-col :span="12">
            <el-form-item label="排序" prop="sort"
                :rules="[
                 ]">
              <el-input v-model="inputForm.sort" placeholder="请填写排序"     ></el-input>
           </el-form-item>
        </el-col> -->
        <el-col :span="12">
            <el-form-item label="备注信息" prop="remarks"
                :rules="[
                 ]">
          <el-input type="textarea" v-model="inputForm.remarks" placeholder="请填写备注信息"     ></el-input>
           </el-form-item>
        </el-col>
        </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button size="small" v-if="method === 'add'" type="primary" @click="continueDoSubmit()">继续添加</el-button>
      <el-button size="small" @click="visible = false">关闭</el-button>
      <el-button size="small" v-if="method !== 'view'" type="primary" @click="doSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        title: '',
        method: '',
        visible: false,
        oldInputForm: '',
        inputForm: {
          id: '',
          fullEducation: '',
          fullGraduate: '',
          fullStart: '',
          fullEnd: '',
          nowEducation: '',
          nowGraduate: '',
          nowStart: '',
          nowEnd: '',
          lastEducation: '',
          sort: '',
          remarks: ''
        }
      }
    },
    components: {
    },
    methods: {
      init (method, obj) {
        this.method = method
        if (method === 'add') {
          this.title = `新建人员学历表`
        } else if (method === 'edit') {
          this.title = '修改人员学历表'
        } else if (method === 'view') {
          this.title = '查看人员学历表'
        }
        this.visible = true
        this.$nextTick(() => {
          this.$refs.inputForm.resetFields()
          this.inputForm.id = ''
          this.oldInputForm = ''
          if (method === 'edit' || method === 'view') { // 修改或者查看
            this.oldInputForm = obj
            this.inputForm = JSON.parse(JSON.stringify(obj))
          }
        })
      },
   // 表单提交
      doSubmit () {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.$emit('addRow', this.oldInputForm, JSON.parse(JSON.stringify(this.inputForm)))
            this.visible = false
          }
        })
      },
      continueDoSubmit () {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.$emit('addRow', this.oldInputForm, JSON.parse(JSON.stringify(this.inputForm)))
            this.$refs['inputForm'].resetFields()
          }
        })
      }
    }
  }
</script>
